<template>
  <a-upload
    name="file"
    :multiple="true"
    :accept="accept"
    :headers="headers"
    :remove="handleRemove"
    @change="handleChange"
    :beforeUpload="beforeUploadway"
    :customRequest="customRequestway"
  >
    <a-button> <a-icon type="upload" />点击上传</a-button>
  </a-upload>
</template>
  <script>
  export default {
    data () {
      return {
        // ,.png,.jpg,
        accept: '.zip,.exe',
        // accept:[".zip",".exe"],
        headers: {
          authorization: 'authorization-text'
        },
        fileList: []
      }
    },
    methods: {
      handleRemove (file) {
        console.log(file)
        const index = this.fileList.indexOf(file)
        const newFileList = this.fileList.slice()
        newFileList.splice(index, 1)
        this.fileList = newFileList
        this.$emit('acceptFile', this.fileList)
      },
      handleChange (fileData) {
        console.log('fileData', fileData)
        if (fileData.file.status !== 'uploading') {

        }
        if (fileData.fileList) {
          if (fileData.fileList.length >= 2) {
            fileData.fileList.splice(0, 1)
          }
        }
        this.fileList = fileData.fileList
        this.$emit('acceptFile', this.fileList)

        if (fileData.file.status === 'done') {
          // this.$message.success(`${fileData.file.name} file uploaded successfully`);
          console.log('done', fileData.file, fileData.fileList) // 正在操作的文件, 操作后的文件列表
          this.fileList = fileData.fileList
          this.$emit('acceptFile', this.fileList)
        } else if (fileData.file.status === 'error') {
          // this.$message.error(`${fileData.file.name} file upload failed.`);
        }
      },
      beforeUploadway (file, fileList) {
        // console.log(file)
        // console.log(fileList)
      },
      customRequestway (file, fileList) {
        console.log('file', file)
        // console.log(fileList)
      }
    }
  }
  </script>
